<?php
require_once("CMongoDB.class.php");
require_once("config.php");
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    echo "ext: ".substr($_FILES["file"]["name"],strrpos($_FILES["file"]["name"], ".")+1). "<br />";
    
      //     move_uploaded_file($_FILES["file"]["tmp_name"],
      // "upload/" . $_FILES["file"]["name"]);
    $type=$_FILES["file"]["type"];
    $ext=substr($_FILES["file"]["name"],strrpos($_FILES["file"]["name"], ".")+1);
    $filename=$_FILES["file"]["tmp_name"];
    $pic=array("uid"=>$uid,"type"=>$type ,"metadata"=>array("ext"=>$ext) );
//	$pic=array("type"=>$type ,"metadata"=>array("ext"=>$ext) );
    $mongoDb = new CMongoDB($config['mongo'] );
    
    $res =  $mongoDb->getDb()->getGridFS('pictures')->put($filename,$pic);
   
    
    echo $result['result'] = $res;
    
//       if($res){
//          echo $result['id'] = $res['$id'] .'';
//        } 
        
    }

?>